package link.config;

import android.support.annotation.Nullable;
import java.util.ArrayList;
import link.model.ConfigInfoVo;
import org.an.ku.util.ACache;
import org.an.proj.contacts.MyApplication;

/**
 * Created by an on 2016/12/18.<br/>
 * 配置信息
 */

public class UIConfig {
  private static final String CONFIG_NAME = "UIConfig";
  private static final String KEY_CONFIGINFO = "configInfo";

  private static UIConfig mInstance;
  private ACache mACache;

  private UIConfig() {
    mACache = ACache.get(MyApplication.getInstance(), CONFIG_NAME);
  }

  public static UIConfig getInstance() {
    if (mInstance == null) {
      synchronized (UIConfig.class) {
        if (mInstance == null) {
          mInstance = new UIConfig();
        }
      }
    }
    return mInstance;
  }

  public void setConfigInfo(@Nullable ConfigInfoVo configInfoVo) {
    if (configInfoVo != null) {
      mACache.put(KEY_CONFIGINFO, configInfoVo);
    }
  }

  @Nullable public ConfigInfoVo getConfigInfo() {
    return (ConfigInfoVo) mACache.getAsObject(KEY_CONFIGINFO);
  }

  public ConfigInfoVo.ConfigItemList getConfigByMode() {
    // 根据当前模式判断取那个配置
    return getNewHouseConfig();
  }

  private ConfigInfoVo.ConfigItemList getNewHouseConfig() {
    ConfigInfoVo configInfoVo = getConfigInfo();
    return configInfoVo != null && configInfoVo.configNewHouse != null ? configInfoVo.configNewHouse
      : new ConfigInfoVo.ConfigItemList();
  }

  public ArrayList<ConfigInfoVo.ConfigItemInfoVo> getTab() {
    ConfigInfoVo.ConfigItemList config = getConfigByMode();
    return config.tab != null ? config.tab : new ArrayList<ConfigInfoVo.ConfigItemInfoVo>();
  }

  public ArrayList<ConfigInfoVo.ConfigItemInfoVo> getBanner() {
    ConfigInfoVo.ConfigItemList config = getConfigByMode();
    return config.banner != null ? config.banner : new ArrayList<ConfigInfoVo.ConfigItemInfoVo>();
  }
}
